var o = getApp();

Page({
    data: {
        imgUrls: [ "../../pic/prodetail.jpg", "../../pic/prodetail.jpg" ],
        id: "",
        goods: {},
        banners: [],
        baseUrl: o.globalData.baseUrl,
        contentImgs: []
    },
    onLoad: function(a) {
        this.setData({
            id: a.id
        });
        var t = o.globalData.urlBase + o.globalData.urlGoodsDetail;
        this.getinitData(t);
    },
    getinitData: function(o) {
        var a = this;
        wx.request({
            url: o,
            data: {
                goodsId: a.data.id
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(o) {
                var t = JSON.parse(o.data);
                0 != t.code ? wx.showToast({
                    title: t.msg,
                    icon: "none",
                    duration: 2e3
                }) : a.setData({
                    goods: t.goods,
                    banners: t.goods.imgs.split(","),
                    contentImgs: t.goods.content.split(","),
                    shareName: t.goods.name ? t.goods.name : "",
                    shareImg: t.goods.imgs.split(",")[0] ? t.goods.imgs.split(",")[0] : ""
                });
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function(o) {
        var a = this;
        return "button" === o.from ? (console.log("来自页面内转发按钮"), console.log(o.target)) : console.log("来自右上角转发菜单"), 
        {
            title: a.data.shareName,
            imageUrl: a.data.baseUrl + "download?id=" + a.data.shareImg,
            success: function(o) {
                console.log("转发成功", o);
            },
            fail: function(o) {
                console.log("转发失败", o);
            }
        };
    },
    purchasee: function() {
        var a = this;
        o.globalData.goodsId = a.data.id, wx.navigateTo({
            url: "../purchase/purchase?id=" + a.data.id
        });
    }
});